package cn.org.rookie.jeesdp.core.component;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ConfigurableBootstrapContext;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.SpringApplicationRunListener;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.ConfigurableEnvironment;

import java.time.Duration;

/**
 * @author LHT
 * @date 2021-12-02 22:34
 */

public class JeesdpApplicationRunListener implements SpringApplicationRunListener {

    private final Logger logger = LoggerFactory.getLogger(JeesdpApplicationRunListener.class);
    private final SpringApplication application;
    private final String[] args;

    public JeesdpApplicationRunListener(SpringApplication application, String[] args) {
        this.application = application;
        this.args = args;
    }

    @Override
    public void starting(ConfigurableBootstrapContext bootstrapContext) {
        SpringApplicationRunListener.super.starting(bootstrapContext);
    }

    @Override
    public void environmentPrepared(ConfigurableBootstrapContext bootstrapContext, ConfigurableEnvironment environment) {
        SpringApplicationRunListener.super.environmentPrepared(bootstrapContext, environment);
    }

    @Override
    public void contextPrepared(ConfigurableApplicationContext context) {

    }

    @Override
    public void contextLoaded(ConfigurableApplicationContext context) {

    }

    @Override
    public void started(ConfigurableApplicationContext context, Duration timeTaken) {
        /*ClassPathResource resource = new ClassPathResource("META-INF/resources.json");
        try {
            List<Resource> resources = BeanUtils.toObjectList(resource.getContentAsByteArray(), Resource.class);
            ResourcesContext.addResources(resources);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }*/
    }

    @Override
    public void ready(ConfigurableApplicationContext context, Duration timeTaken) {
        SpringApplicationRunListener.super.ready(context, timeTaken);
    }

    @Override
    public void failed(ConfigurableApplicationContext context, Throwable exception) {
        SpringApplicationRunListener.super.failed(context, exception);
    }
}
